<template>
  <div class="jsgltck_box">
    <div class="jsgltck">
      <div class="head_clos">
        <h2 v-if="$store.state.shdzbj==false">收货地址</h2>
        <h2 v-if="$store.state.shdzbj==true">修改收货地址</h2>
        <span v-if="this.$store.state.tjhy">
          <a-icon class="close" @click="close" type="close" />
        </span>
      </div>
      <div class="jsgltck_inp">
        <ul>
         
          <li>
            <span class="inp_tit">收货人：</span>
            <a-input v-model="shr" style="width:500px" type="text" placeholder="请输入收货人" />
          </li>
          <li>
            <span class="inp_tit">联系电话：</span>
            <a-input v-model="lxdh" style="width:500px" type="text" placeholder="请输入联系电话" />
          </li>
          <li>
            <span class="inp_tit">收货地址：</span>
            <a-input v-model="shdz" style="width:500px" type="text" placeholder="请输入收货地址" />
          </li>
          <li>
            <span class="inp_tit">默认：</span>
            <a-radio-group @change="onChange" v-model="mrbj">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
            </a-radio-group>
          </li>
          <li class="foot_btn">
            <a-button class="sub" @click="shdzsub">保存</a-button>
         
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import qs from "qs";
export default {
  data() {
    return {
      mrbj: "1",
      gsmc: "",
      shr: "",
      lxdh: "",
      shdz: ""
    };
  },
  components: {},
  methods: {
    onChange(e) {
      console.log("radio checked", e.target.value);
    },
    shdzsub() {
      if (this.shr != "" && this.lxdh != "" && this.shdz != "") {
        if (this.$store.state.shdzbj == false) {
          this.axios
            .post(
              "huiyuan/Addaddress.php",
              qs.stringify({
                sqdwid: this.$store.state.bbl_sqdwid,
                phone: this.$store.state.bbl_phone,
                hyphone: this.$parent.kpxxphone,
                gsmc: this.shr,
                lxdh: this.lxdh,
                beizhu: this.shdz,
                mrbj: this.mrbj,

                shr: this.shr
              })
            )
            .then(res => {
              console.log(res);
              if (res.data.code == 303) {
                this.$notification["success"]({
                  message: "成功",
                  description: res.data.msg
                });
                this.$store.state.tjhy = false;
                this.$store.state.shdzbj = false;
                this.$parent.getaddressList();
              } else {
                this.$notification["error"]({
                  message: "失败",
                  description: res.data.msg
                });
              }
            });
        } else {
          this.axios
            .post(
              "huiyuan/editAddress.php",
              qs.stringify({
                id_num: this.$store.state.editAddress.ID_NUM,
                sqdwid: this.$store.state.bbl_sqdwid,
                phone: this.$store.state.bbl_phone,
                hyphone: this.$parent.kpxxphone,
                gsmc: this.shr,
                lxdh: this.lxdh,
                beizhu: this.shdz,
                mrbj: this.mrbj,

                shr: this.shr
              })
            )
            .then(res => {
              console.log(res);
              if (res.data.code == 303) {
                this.$notification["success"]({
                  message: "成功",
                  description: res.data.msg
                });
                this.$store.state.tjhy = false;
                this.$store.state.shdzbj = false;
                this.$parent.getaddressList();
              } else {
                this.$notification["error"]({
                  message: "失败",
                  description: res.data.msg
                });
              }
            });
        }
      }
    },
    close() {
      this.$store.state.tjhy = false;
      this.$store.state.shdzbj = false;
    }
  },

  created() {
    if (this.$store.state.shdzbj == true) {

      this.mrbj = this.$store.state.editAddress.MRBJ;
      if (this.mrbj == "是") {
        this.mrbj = "1";
      } else {
        this.mrbj = "0";
      }
      this.shr = this.$store.state.editAddress.GSMC;
      this.shdz = this.$store.state.editAddress.NR;
      this.lxdh = this.$store.state.editAddress.lxdh;
    }
  }
};
</script>

<style lang='less' >
.jsgltck_box {
  position: relative;
  .jsgltck {
    width: 66%;
    height: auto;
    box-shadow: 0px 0px 7px #ccc;
    background-color: #fff;
    margin: 9px auto;
    position: relative;
    top: 63px;
    text-align: left;
    padding: 20px;
    .head_clos {
      display: flex;
      justify-content: space-between;
      .close {
        font-size: 20px;
      }
    }
    .jsgltck_inp {
      ul {
        max-height: 700px;
        overflow-y: scroll;
        li {
          margin: 20px 0;
          .inp_tit {
            display: inline-block;
            width: 100px;
            text-align: right;
          }
          .ant-checkbox-group {
            width: 500px;
            vertical-align: top;
          }
          .ant-checkbox-group-item {
            width: 100% !important;
          }
        }
        .foot_btn {
          width: 100%;
          text-align: right;
          button {
            margin: 0 20px;
          }
          .sub {
            background-color: #f95b67;
            border-color: #f95b67;
            color: #fff;
          }
        }
      }
    }
  }
}
</style>
